<template><div><h1 id="环境搭建" tabindex="-1"><a class="header-anchor" href="#环境搭建" aria-hidden="true">#</a> 环境搭建</h1>
<p><a href="https://docs.flutter.dev/" target="_blank" rel="noopener noreferrer">官方文档<ExternalLinkIcon/></a></p>
<h2 id="_1-获取-flutter-sdk" tabindex="-1"><a class="header-anchor" href="#_1-获取-flutter-sdk" aria-hidden="true">#</a> 1.获取 <code v-pre>Flutter SDK</code></h2>
<p>下载安装包以获取<code v-pre>Flutter SDK</code>的最新稳定版本：</p>
<p><a href="https://storage.googleapis.com/flutter_infra_release/releases/stable/windows/flutter_windows_3.7.12-stable.zip" target="_blank" rel="noopener noreferrer">flutter_windows_3.7.12-stable.zip <ExternalLinkIcon/></a></p>
<p>下载好安装包之后解压</p>
<blockquote>
<p><strong>注意</strong>：不要将 flutter 安装到需要一些高权限的路径如 <code v-pre>C:\Program Files\</code></p>
</blockquote>
<h2 id="_2-配置环境变量" tabindex="-1"><a class="header-anchor" href="#_2-配置环境变量" aria-hidden="true">#</a> 2.配置环境变量</h2>
<p>我的电脑&gt;属性&gt;高级系统设置&gt;环境变量&gt;在用户变量中的<code v-pre>Path</code>中添加<code v-pre>flutte\bin</code>目录的路径</p>
<h2 id="_3-执行-flutter-doctor" tabindex="-1"><a class="header-anchor" href="#_3-执行-flutter-doctor" aria-hidden="true">#</a> 3.执行 flutter doctor</h2>
<ul>
<li>找到解压 flutter 目录下的 <code v-pre>flutter_console.bat</code>，双击执行</li>
<li>执行 flutter doctor 检测是否安装完成</li>
</ul>
<h2 id="_4-安装android-studio" tabindex="-1"><a class="header-anchor" href="#_4-安装android-studio" aria-hidden="true">#</a> 4.安装Android Studio</h2>
<p><a href="https://developer.android.google.cn/studio" target="_blank" rel="noopener noreferrer">下载地址<ExternalLinkIcon/></a></p>
<p>https://blog.csdn.net/tao_789456/article/details/118093106</p>
<h2 id="_5-配置flutter镜像" tabindex="-1"><a class="header-anchor" href="#_5-配置flutter镜像" aria-hidden="true">#</a> 5.配置Flutter镜像</h2>
<p>我的电脑&gt;属性&gt;高级系统设置&gt;环境变量</p>
<blockquote>
<div class="language-cpp line-numbers-mode" data-ext="cpp"><pre v-pre class="language-cpp"><code>PUB_HOSTED_URL<span class="token operator">=</span>https<span class="token operator">:</span><span class="token comment">//pub.flutter-io.cn</span>

FLUTTER_STORAGE_BASE_URL<span class="token operator">=</span>https<span class="token operator">:</span><span class="token comment">//storage.flutter-io.cn</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></blockquote>
<h2 id="_6-问题" tabindex="-1"><a class="header-anchor" href="#_6-问题" aria-hidden="true">#</a> 6.问题</h2>
<h3 id="windows-version-installed-version-of-windows-is-version-10-or-higher" tabindex="-1"><a class="header-anchor" href="#windows-version-installed-version-of-windows-is-version-10-or-higher" aria-hidden="true">#</a> <code v-pre>Windows Version (Installed version of Windows is version 10 or higher)</code></h3>
<ol>
<li>
<p>该目录下的文件：（<code v-pre>FLUTTER-SDK-DIR</code>）<code v-pre>\packages\flutter_tools\lib\src\windows\windows_version_validator.dart</code></p>
<p>其实是<code v-pre>windows</code>中文环境输出的内容是不一样的，国外用的是<code v-pre>OS Version</code>作为正则表达式，我们国内改成：<code v-pre>OS 版本</code>，所以只需要修改如下代码即可</p>
<div class="language-dart line-numbers-mode" data-ext="dart"><pre v-pre class="language-dart"><code><span class="token keyword">const</span> <span class="token class-name">String</span> kWindowsOSVersionSemVerPattern <span class="token operator">=</span>
	<span class="token string-literal"><span class="token string">r'^(OS 版本:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)$'</span></span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div></li>
<li>
<p>删除文件。<code v-pre>（FLUTTER-SDK-DIR）</code> <code v-pre>\bin\cache\flutter_tools.stamp/</code></p>
</li>
<li>
<p>再跑一次。flutter doctor</p>
</li>
</ol>
<h3 id="android-toolchain-develop-for-android-devices" tabindex="-1"><a class="header-anchor" href="#android-toolchain-develop-for-android-devices" aria-hidden="true">#</a> <code v-pre>Android toolchain - develop for Android devices</code></h3>
<p><code v-pre>Android SDK</code> 安装</p>
<p><code v-pre>Android Studio</code> &gt; <code v-pre>Settings</code> &gt; <code v-pre>SDK Tools</code> &gt; <code v-pre>Android SDK Command-line Tools (latest)</code></p>
<div class="language-bash line-numbers-mode" data-ext="sh"><pre v-pre class="language-bash"><code>// D:<span class="token punctuation">\</span>AndroidTool<span class="token punctuation">\</span>AndroidSDK SDK安装路径
flutter config --android-sdk D:<span class="token punctuation">\</span>AndroidTool<span class="token punctuation">\</span>AndroidSDK
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="visual-studio-develop-for-windows" tabindex="-1"><a class="header-anchor" href="#visual-studio-develop-for-windows" aria-hidden="true">#</a> <code v-pre>Visual Studio - develop for Windows</code></h3>
<p>安装<a href="https://visualstudio.microsoft.com/downloads/" target="_blank" rel="noopener noreferrer">Visual Studio 2022<ExternalLinkIcon/></a>或<a href="https://visualstudio.microsoft.com/downloads/https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022" target="_blank" rel="noopener noreferrer">Visual Studio Build Tools 2022<ExternalLinkIcon/></a>，需要安装用于生成窗口的“使用C++进行桌面开发”工作负载，包括其所有默认组件。</p>
<h3 id="http-host-not-reachable" tabindex="-1"><a class="header-anchor" href="#http-host-not-reachable" aria-hidden="true">#</a> <code v-pre>HTTP host not reachable</code></h3>
<div class="language-bash line-numbers-mode" data-ext="sh"><pre v-pre class="language-bash"><code>HTTP <span class="token function">host</span> https://maven.google.com/ is not reachable.Reason: An error occurred <span class="token keyword">while</span> checking the HTTP <span class="token function">host</span>

HTTP <span class="token function">host</span> https://cloud.google.com/ is not reachable.Reason: An error occurred <span class="token keyword">while</span> checking the HTTP <span class="token function">host</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ol>
<li>
<p>找到<code v-pre>flutter sdk</code>的文件目录，打开下面路径文件</p>
<blockquote>
<p><code v-pre>flutter\packages\flutter_tools\lib\src\http_host_validator.dart</code></p>
</blockquote>
</li>
<li>
<p>将文件中的链接进行替换</p>
<blockquote>
<p>将其中的 <code v-pre>https://maven.google.com/</code> 修改为 <code v-pre>https://dl.google.com/dl/android/maven2/</code>（解决第一个问题）
再将 <code v-pre>kPubDevHttpHost</code> 和 <code v-pre>kgCloudHttpHost</code> 两个常量 分别修改为 <code v-pre>https://pub.flutter-io.cn/</code> 和 <code v-pre>https://storage.flutter-io.cn/</code>（解决第二个）</p>
</blockquote>
</li>
<li>
<p>去到<code v-pre>flutter\bin</code>目录，删除<code v-pre>cache</code>目录下的<code v-pre>flutter_tools.snapshot</code> 文件</p>
</li>
<li>
<p>新开一个<code v-pre>cmd</code>，在<code v-pre>cmd</code>命令窗口重新运行<code v-pre>flutter doctor</code>,问题解决。</p>
</li>
</ol>
<h2 id="_7-项目运行" tabindex="-1"><a class="header-anchor" href="#_7-项目运行" aria-hidden="true">#</a> 7. 项目运行</h2>
<ul>
<li>查看版本号</li>
</ul>
<div class="language-powershell line-numbers-mode" data-ext="powershell"><pre v-pre class="language-powershell"><code>flutter <span class="token operator">--</span>version
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul>
<li>检查开发环境是</li>
</ul>
<div class="language-powershell line-numbers-mode" data-ext="powershell"><pre v-pre class="language-powershell"><code>flutter doctor
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul>
<li>下载依赖</li>
</ul>
<div class="language-bash line-numbers-mode" data-ext="sh"><pre v-pre class="language-bash"><code>flutter packages get
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul>
<li>运行项目</li>
</ul>
<div class="language-bash line-numbers-mode" data-ext="sh"><pre v-pre class="language-bash"><code>flutter run
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div></div></template>


